# -*- coding: utf-8 -*-


import  wx
import  os
import  wx.wizard as wiz

#import  images
import  encodings.mbcs
import  codecs
import GenericTable
import wx.grid
import validator
import wizdata
import wizpages



from db import *
import savedata as sdata

from util import *

from time import *
from time import time, strftime, localtime

import time, random, md5




class DonePage(wiz.PyWizardPage):
    def __init__(self, parent, title):
        wiz.PyWizardPage.__init__(self, parent)
        self.next = self.prev = None
        
        self.emp_exist = None
        self.title = title
        self.built = None
        self.sizer = wx.GridBagSizer(hgap=5, vgap=5)
        #wizPg.SetSizer(sizer)
        #self.BuildPanel()
        
        
        
    def OnSave(self, event):
        
        start = strftime("%Y-%m-%d %H:%M:%S", localtime())
        self.multiText.AppendText(start + ' Begin'+"\n")
        data = wizdata.WizData()
        
        x = data.option
        
        if x >1:
            pages = wizpages.WizPages()
            data.newcollist = pages.page5.GetCol()
        
        savedata = sdata.SaveData(data)
        #print data.col_list
        
        #print x
        if x == 3:   
            #self.SaveNewCol()
            savedata.saveNewMap()
            pass

        elif x == 2:  
            savedata.saveNewMap()
            pass
        elif x == 1:
            pass
            
        
        savedata.saveExcel() #
        
        

        
        self.save.Enable(False)
        end = strftime("%Y-%m-%d %H:%M:%S", localtime())
        self.multiText.AppendText(end + ' End'+"\n")
        event.Skip()
        

        
    def BuildPanel(self):
        self.built = 1
        title = wx.StaticText(self, -1, self.title)
        title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
        self.sizer.Add(title, pos = (0,1),span = (1,4))      
        
        self.save = wx.Button(self, -1, u"保存信息")
        self.Bind(wx.EVT_BUTTON, self.OnSave, self.save)
        self.sizer.Add(self.save, pos=(1,1))
        
        self.multiText = wx.TextCtrl(self, -1,
               u"Log:\n",
               size=(500, 200), style=wx.TE_MULTILINE)
        
        self.multiText.SetInsertionPoint(1)

        self.sizer.Add(self.multiText, pos = (2,1))

        self.SetSizer(self.sizer)
        self.Fit()
        

    def SetNext(self, next):
        self.next = next
      
    def SetPrev(self, prev):
        self.prev = prev
    
    def GetNext(self):
        next = self.next
        return next
        
    def GetPrev(self):
        return self.prev  

class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "", size=(800, 660)) 
        wizard = wiz.Wizard(self, -1, u"Done")
        page1 = DonePage(wizard, u"Done")
        wizard.FitToPage(page1)
        wizard.RunWizard(page1)

def test():
    data = wizdata.WizData()
    
    data.filename = 'a1.xls'
    data.mapping_id = 1
    data.pstart = '2007-09-19'
    data.pend = '2007-09-19'
    data.inout = '2007-09-19'
    
    data.mappingtype = u"工资表"
    data.map_name = "new map"
    data.col_list = u'["a","b"]'
    data.mapping=u'["项目","姓名"]'
    data.rowstart = 1
    data.colstart = 1
    data.ignore_last = 0
    
    app = wx.PySimpleApp()
    TestFrame().Show()
    app.MainLoop() 


if __name__ == "__main__":
    test()
